'use strict'
let globalObject = require('../server/globalobject')
let TcpClient = require('./connector').TcpClient

let net = require('net')
let Transport = require('./transport')

class NodeClient {
	constructor(name) {
		this.name = name
		this.tcpClient = new TcpClient(name)
		this.transport = null
		this._remoteCall = {} //注册的远程回调函数
	}

	connect(port, ip) {
		let self = this
		this.tcpClient.connect(port, ip)

		this.transport = new Transport(this.tcpClient.socket, self)
			//向远程服务端发送代理通道对象
		let msg = {
			name: self.name
		}
		this.transport.callRemote('register', msg)

	}

	//作为root服务器节点，供remote节点调用的接口描述符
	rootRemote(msgName, cb) {
		this._remoteCall[msgName] = cb
	}

	getRemoteMothed(msgName) {
		return this._remoteCall[msgName]
	}

}

module.exports = NodeClient
